package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.*;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zx
 */
@Component
public class XunFeiCommonApiService extends  XunFeiApiService{


    public ApiListResponse<ResourceTypeResp> getResourceType(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/resource/type",params);
        if(httpResult.isSuccess()){
            ApiListResponse<ResourceTypeResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<ResourceTypeResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
     }


    public ApiListResponse<TestCountryItemListResp> getTestCountryItem(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/physical/test/country/item/info",params);
        if(httpResult.isSuccess()){
            ApiListResponse<TestCountryItemListResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<TestCountryItemListResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }




    public ApiListResponse<ResourceTypeListResp> getResourceTypeList(QueryResourceTypeListReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/resource/list",params);
        if(httpResult.isSuccess()){
            ApiListResponse<ResourceTypeListResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<ResourceTypeListResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public ApiListResponse<PhysicalTestItemResp> getPhysicalTestItem(QueryPhysicalTestItemReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/physical/test/item",params);
        if(httpResult.isSuccess()){
            ApiListResponse<PhysicalTestItemResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<PhysicalTestItemResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    public ApiListResponse<TestCycleResp> getTestCycle(QueryTestCycleReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/physical/test/cycle",params);
        if(httpResult.isSuccess()){
            ApiListResponse<TestCycleResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<TestCycleResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    public ApiListResponse<DeviceInfoResp> getDeviceInfo(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/device/info/school",params);
        if(httpResult.isSuccess()){
            ApiListResponse<DeviceInfoResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<DeviceInfoResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public ApiListResponse<DeviceInfoStatisticResp> getDeviceInfoStatistic(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/device/info/school/statistic",params);
        if(httpResult.isSuccess()){
            ApiListResponse<DeviceInfoStatisticResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<DeviceInfoStatisticResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public ApiListResponse<DeviceInfoBaseStationResp> getDeviceInfoBaseStation(QueryDeviceInfoBaseStationReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/device/info/basestation/"+request.getKeyId()+"/"+request.getType(),params);
        if(httpResult.isSuccess()){
            ApiListResponse<DeviceInfoBaseStationResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<DeviceInfoBaseStationResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    public ApiSingleResponse<SportConfigCourseResp> getSportConfigCourse(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/sport/config/course",params);
        if(httpResult.isSuccess()){
            ApiSingleResponse<SportConfigCourseResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<SportConfigCourseResp>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    public ApiListResponse<SportConfigHeart> getSportConfigHeart(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/sport/config/heart",params);
        if(httpResult.isSuccess()){
            ApiListResponse<SportConfigHeart> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<SportConfigHeart>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public ApiListResponse<SportItemListResp> getSportItemList(XunFeiApiRequest request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/sport/item/list",params);
        if(httpResult.isSuccess()){
            ApiListResponse<SportItemListResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<SportItemListResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    public ApiListResponse<SportItemRuleResp> getSportItemRule(QuerySportItemRuleReq request, String sid, String did, String uid){
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/sport/item/rule",params);
        if(httpResult.isSuccess()){
            ApiListResponse<SportItemRuleResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<SportItemRuleResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }


    public static void main(String[] args) {
        XunFeiCommonApiService xunFeiApiService=new XunFeiCommonApiService();
//        QueryTestCycleReq queryTestCycleReq =new QueryTestCycleReq();
//        queryTestCycleReq.setTeachCycleId("1");
//        queryTestCycleReq.setType("2");
//        System.out.println(xunFeiApiService.getTestCycle(queryTestCycleReq,"87", null,"3"));

        XunFeiApiRequest xunFeiApiRequest=new XunFeiApiRequest();
        System.out.println(xunFeiApiService.getTestCountryItem(xunFeiApiRequest,"87", null,"3"));


//        System.out.println(xunFeiApiService.getDeviceInfoStatistic(xunFeiApiRequest,"87", null,"3"));

//        QueryDeviceInfoBaseStationReq queryDeviceInfoBaseStationReq=new QueryDeviceInfoBaseStationReq();
//        queryDeviceInfoBaseStationReq.setKeyId("f09955497d6d4f5285c74ea2ccadc4e8");
//        queryDeviceInfoBaseStationReq.setType("1");
//        System.out.println(xunFeiApiService.getDeviceInfoBaseStation(queryDeviceInfoBaseStationReq,"87", null,"3"));
//

//        QueryPhysicalTestItemReq req =new QueryPhysicalTestItemReq();
//        req.setType("");
//        System.out.println(xunFeiApiService.getPhysicalTestItem(req,"87", null,"3"));


//        XunFeiApiRequest xunFeiApiRequest =new XunFeiApiRequest();
        //System.out.println(xunFeiApiService.getSportConfigCourse(xunFeiApiRequest,"87", null,"3"));
//        System.out.println(xunFeiApiService.getSportItemList(xunFeiApiRequest,"87", null,"3"));

//        QuerySportItemRuleReq querySportItemRuleReq =new QuerySportItemRuleReq();
//        querySportItemRuleReq.setItemId("101");
//        querySportItemRuleReq.setGender("1");
//        System.out.println(xunFeiApiService.getSportItemRule(querySportItemRuleReq,"87", null,"3"));

    }

}

